#ifndef GENERATOR_H
#define GENERATOR_H
#include <QByteArray>
#include <QIODevice>
#include <QFile>
#include <QAudioFormat>
#include <QAudioOutput>
#include <libavinclude.h>
#include <queue>
#include <libavinclude.h>
#include "Task_Base/CriticalSection.h"
using namespace std;
class Generator : public QIODevice
{
    Q_OBJECT
public:
    Generator(AVStream *,AVCodec *);

    ~Generator();
public:
    void appendAudioPacket(const AVPacket &);

    void start();
    void stop();

    qint64 readData(char *data, qint64 maxlen);

    qint64 writeData(const char *data, qint64 len);

    qint64 bytesAvailable() const;

    double get_audio_clock();
private:

    bool PopAudioPacket(AVPacket &);

private:
    qint64 m_pos;
    QByteArray m_buffer;

    CCriticalSection oCriSection;

    std::queue<AVPacket>  m_AVPacketList;

    AVStream        *m_pAVStream;

    AVFrame         *m_pFrame;

    AVCodec        *m_pAVCodec;

    struct SwrContext *au_convert_ctx;

    uint8_t          *out_buffer;

    int             out_buffer_size;

    unsigned int     audio_buf_size;

    unsigned int     audio_buf_index;

    double              audio_clock;

    int audio_decode_frame();
};

#endif // GENERATOR_H
